package dao.impl;

import dao.UserDao;
import util.JDBCUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class UserDaoImpl implements UserDao {
    @Override
    public String select(String name, String password) throws Exception {

//            获取链接
        Connection conn = JDBCUtils.getconnection();
//            获取数据库操作对象
        Statement stat = conn.createStatement();
        ResultSet rs = null;
        String identity = "null";
        try {
//            执行SQL语句
            String str = "SELECT * FROM user WHERE name = " + "'" + name + "'" + " and password = " + "'" + password + "'";
            System.out.println(str);
            rs = stat.executeQuery(str);
            while(rs.next()) {
                identity = rs.getString("identity");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
//            释放资源
            JDBCUtils.release(rs,stat,conn);
        }
        return identity;
    }
}
